﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TTBusiness.ClassDB;
using TTBusiness.DB_Linq;
using TTBusiness;
namespace TTMarketing.Admin
{
    public partial class StatusProduct : System.Web.UI.Page
    {
        clsBSStatusProduct objDB = new clsBSStatusProduct();
        protected void Page_Load(object sender, EventArgs e)
        {
            divmessage.InnerHtml = "";
            divmessage2.InnerHtml = "";
            if(!Page.IsPostBack)
            this.rgdGrid.Rebind();
        }

        protected void cmbClose_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (Convert.ToInt32(e.Value) == 1)
            {
                plDetail.Visible = true;
            }
            else
            {
                plDetail.Visible = false;
            }
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {

                tblStatus_Product obj = new tblStatus_Product();
                obj.ProductID = Convert.ToInt32(this.cmbProduct.SelectedValue);
                obj.StatusID = Convert.ToInt32(this.cmbStatus.SelectedValue);
                objDB.insert(obj);
                divmessage.InnerHtml = clsBSMessageAdmin.MessageSuccess("Thành công : ", "Cập nhật thành công").ToString();
                this.rgdGrid.Rebind();
                this.cmbStatus.DataBind();
            }
            catch (Exception ex)
            {
                divmessage.InnerHtml = clsBSMessageAdmin.MessageError("Lỗi : ", "Gặp lỗi không thể cập nhật : " + ex.Message).ToString();
            }
        }

        protected void rgdGrid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("delete"))
                {
                    objDB.delete(Convert.ToInt32(e.CommandArgument));
                    divmessage2.InnerHtml = clsBSMessageAdmin.MessageSuccess("Thành công : ", "Đã xóa thành công!").ToString();
                    this.rgdGrid.Rebind();
                    this.cmbStatus.DataBind();
                }
            }
            catch (Exception)
            {
                divmessage2.InnerHtml = clsBSMessageAdmin.MessageError("Lỗi : ", "Gặp lỗi không thể xóa được").ToString();
            }
        }

        protected void cmbProduct_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            try
            {
                this.rgdGrid.Rebind();
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        protected void cmbProduct_DataBound(object sender, EventArgs e)
        {
            try
            {
                this.rgdGrid.Rebind();
            }
            catch (Exception)
            {
                
                throw;
            }
        }
    }
}